package com.zxl.working.mapper.admin;

import com.zxl.working.entity.admin.*;
import com.zxl.working.entity.backend.SellerBill;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

@Mapper
@Qualifier("adminSqlSessionTemplate")
public interface UserMapper {

    @Select("select * from sys_user where login_name = #{loginName} and valid='Y'")
    @Results({
            @Result(property = "userId",column = "user_id"),
            @Result(property = "loginName",column = "login_name"),
            @Result(property = "userName",column = "user_name"),
            @Result(property = "password",column = "password"),
            @Result(property = "valid",column = "valid"),
            @Result(property = "limitedIp",column = "limited_ip"),
            @Result(property = "expiredTime",column = "expired_time"),
            @Result(property = "lastChangePwdTime",column = "last_change_pwd_time"),
            @Result(property = "limitMultiLogin",column = "limit_multi_login"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "merchantNumber",column = "merchant_number"),
            @Result(property = "platform",column = "platform")

    })
    SysUser qryUserByLoginName(@Param("loginName") String loginName);

    @Select("select * from sys_menu a,sys_user_menu b where a.menu_id = b.menu_id and b.user_id = #{userId} order by a.sort_num")
    @Results({
            @Result(property = "menuId",column = "menu_id"),
            @Result(property = "menuName",column = "menu_name"),
            @Result(property = "menuPath",column = "menu_path"),
            @Result(property = "menuParentId",column = "menu_parent_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
            @Result(property = "sortNum",column = "sort_num")
    })
    List<SysMenu> qryMenus(@Param("userId")String userId);


    @Update("update sys_user set password=#{password} where user_id = #{userId}")
    void updatePwd(@Param("userId") String userId,@Param("password") String password);

    @Insert("INSERT INTO `admin`.`sys_user` (" +
            "  `user_id`," +
            "  `login_name`," +
            "  `user_name`," +
            "  `password`," +
            "  `valid`," +
            "  `last_change_pwd_time`," +
            "  `limit_multi_login`," +
            "  `create_time`," +
            "  `update_time`," +
            "  `merchant_number`" +
            ")" +
            "VALUES" +
            "  (" +
            "    #{userId}," +
            "    #{loginName}," +
            "    #{userName}," +
            "    #{password}," +
            "   #{valid}," +
            "   #{lastChangePwdTime}," +
            "    #{limitMultiLogin}," +
            "    #{createTime}," +
            "    #{updateTime}," +
            "    0" +
            "  );")
    void save(SysUser sysUser);


    @Insert("insert into `sys_user_authority`" +
            " values(#{userAuthorityId},#{userId},'2c30082d2a11404bb8852d63c4f4fe74',NOW(),NOW());")
    void saveSysUserAuthority(SysUserAuthority sysUserAuthority);
}
